import $ from "@jquery";
import { onDocumentComplete, watchElement, injectLink } from "@utils";

/**
 *对当前document做额外的处理
 * @param {Function} cb
 */
export function handlePreView(cb) {
  onDocumentComplete(document, function () {
    cb(document);

    watchElement(
      document.body,
      {
        childList: true,
        subtree: true,
      },
      function () {
        /** @type {Document}  editor page`s document */
        const previewIframe = $("#preview-iframe").contents().get()[0];
        previewIframe && cb(previewIframe);
        previewIframe &&
          $(previewIframe).find("#page-content").autoFixDirection();
      }
    );
  });
}
